<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>  
<%@ include file="/WEB-INF/jsp/inc/taglib.jsp" %>
<%-- 设置URL参数 --%>
<c:set var="queryURL" value="${baseURL}/${domainObjectName?uncap_first}" />
<c:set var="viewURL" value="${baseURL}/${domainObjectName?uncap_first}/{0}" />
<c:set var="createURL" value="${baseURL}/${domainObjectName?uncap_first}/create" />
<c:set var="updateURL" value="${baseURL}/${domainObjectName?uncap_first}/{0}/update" />
<c:set var="deleteURL" value="${baseURL}/${domainObjectName?uncap_first}/{0}/delete" />

<c:set var="searchPage" value="query.jsp" />
<c:set var="modelMessageKey" value="${domainObjectName?uncap_first}" />
<%-- 权限设置 --%>
<c:set var="createPermission" value="${permissionPrefix}${domainObjectName?uncap_first }:create" />
<c:set var="updatePermission" value="${permissionPrefix}${domainObjectName?uncap_first }:update" />
<c:set var="deletePermission" value="${permissionPrefix}${domainObjectName?uncap_first }:delete" />
<c:set var="viewPermission" value="${permissionPrefix}${domainObjectName?uncap_first }:view" />


<!DOCTYPE html>
<html>
<head>
<#-- <title>${remarks!''}</title> -->
<title><fmt:message key="${domainObjectName?uncap_first }" /></title>
<%@ include file="/WEB-INF/jsp/inc/inc.jsp"%>
<%@ include file="/WEB-INF/jsp/common/messager.jsp" %>
<script type="text/javascript">
var queryParams={"first":true};
var frozenColumns = [[ ]];
var columns = [[
<#assign flag = true />
<#list table.allColumns as column>
	<#if !(primaryKeyColumns?seq_contains(column))>
		<#if flag >
			<#assign flag=false />
 {width : "100",align : "left", halign : "center", sortable : true, title : "<fmt:message key='${domainObjectName?uncap_first}.${column.javaProperty}'/>",field : "${column.javaProperty}"}
		<#else />
,{width : "100",align : "left", halign : "center", sortable : true, title : "<fmt:message key='${domainObjectName?uncap_first}.${column.javaProperty}'/>",field : "${column.javaProperty}"}
		</#if>	
	</#if>
</#list>
	]];
</script>
<script type="text/javascript">
<shiro:hasPermission name="${r'${viewPermission}'}">
var dataGrid;
$(function() {
	dataGrid = $('#grid').datagrid({
		url : '${r'${pageContext.request.contextPath}' }${r'${queryURL }' }',
		queryParams : queryParams,
		singleSelect : true, resizable:false, remoteSort:false,
		rownumbers : true, pagination : true, pageSize : 10,
		pageList : [ 10, 20, 30, 40, 50, 100, 200, 300, 400, 500 ],
		frozenColumns : frozenColumns,
		columns : columns,
		toolbar : '#toolbar',
		onDblClickRow : function(index,row){
			if(selectModel){selectModel(row.id);}
		},
		onBeforeLoad : function(row, param) {
			openProgress();
		},
		onLoadSuccess : function(row, data) {
			closeProgress();
		}
	});
});
function query(){
	dataGrid.datagrid('load',$.serializeObject($('#searchForm')))
}
</shiro:hasPermission>
</script>
<script type="text/javascript">
var selectModel,createModel,updateModel,deleteModel,viewModel;
selectModel = function(id){
	if(updateModel)
		updateModel(id);
	else if(viewModel)
		viewModel(id);
}
<shiro:hasPermission name="${r'${createPermission}'}">
createModel = function() {
	parent.changeURL("${r'${pageContext.request.contextPath}' }${r'${createURL}' }");
};
</shiro:hasPermission>
<shiro:hasPermission name="${r'${viewPermission}'}">
viewModel = function(id) {
	if(!id){
		var row = dataGrid.datagrid('getSelected');
		if(!row){
			$.easyui.messager.show("<fmt:message key="global.show.title"/>", $.formatString('<fmt:message key="global.show.message.select"/>', '<fmt:message key="${r'${modelMessageKey }' }"/>'), "info", "topCenter",2000);
			return;
		}
		id = row.id;
	}
	parent.changeURL("${r'${pageContext.request.contextPath}' }${r'${viewURL}' }?id="+id);
};
</shiro:hasPermission>
<shiro:hasPermission name="${r'${updatePermission}'}">
updateModel = function(id) {
	if(!id){
		var row = dataGrid.datagrid('getSelected');
		if(!row){
			$.easyui.messager.show("<fmt:message key="global.show.title"/>", $.formatString('<fmt:message key="global.show.message.select"/>', '<fmt:message key="${r'${modelMessageKey }' }"/>'), "info", "topCenter",2000);
			return;
		}
		id = row.id;
	}
	parent.changeURL($.formatString("${r'${pageContext.request.contextPath}' }${r'${updateURL}' }",id));
};
</shiro:hasPermission>
<shiro:hasPermission name="${r'${deletePermission}'}">
deleteModel = function(id) {
	if(!id){
		var row = dataGrid.datagrid('getSelected');
		if(!row){
			$.easyui.messager.show("<fmt:message key="global.show.title"/>", $.formatString('<fmt:message key="global.show.message.delete"/>', '<fmt:message key="${r'${modelMessageKey }' }"/>'), "info", "topCenter",2000);
			return;
		}
		id = row.id;
	}
	$.messager.confirm('<fmt:message key="global.confirm.title"/>', $.formatString('<fmt:message key="global.confirm.message"/>', '<fmt:message key="${r'${modelMessageKey }' }"/>'), function(r) {
		if (r) {
			$.easyui.messager.progress("<fmt:message key="global.progress.tltle"/>","<fmt:message key="global.progress.loading.text"/>");
			var url = $.formatString('${r'${pageContext.request.contextPath}' }${r'${deleteURL}' }',id);
			$.post(url, {}, function(data) {
				if (data.success) {
					success();dataGrid.datagrid('reload');
				}else{error();}
			}, 'json');
		}
	});
};
</shiro:hasPermission>
</script>
</head>
<body>
<div class="easyui-layout" data-options="fit:true,border:false">
	<div id="toolbar" style="display: none;">
		<jsp:include page="${r'${searchPage }' }" />
	</div>
	<div data-options="region:'center',fit:false,border:false">
		<table id="grid" data-options="fit:true,border:false"></table>
	</div>
	<div data-options="region:'east',fit:false,border:false,split:true" class="btns">
		<ul class="btns">
			<shiro:hasPermission name="${r'${viewPermission}'}">
			<li><a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'',plain:false" onclick="query()"><fmt:message key="global.button.query"/></a></li>
			</shiro:hasPermission>
			<shiro:hasPermission name="${r'${createPermission}'}">
			<li><a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'',plain:false" onclick="createModel();"><fmt:message key="global.button.add"/></a></li>
			</shiro:hasPermission>
			<shiro:hasPermission name="${r'${updatePermission}'}">
			<li><a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'',plain:false" onclick="selectModel();"><fmt:message key="global.button.select"/></a></li>
			</shiro:hasPermission>
			<shiro:hasPermission name="${r'${deletePermission}'}">
			<li><a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'',plain:false" onclick="deleteModel();"><fmt:message key="global.button.delete"/></a></li>
			</shiro:hasPermission>
		</ul>
	</div>
</div>
</body>
</html>